package com.gk.panda.apis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.panda.apis.entity.eventtodo.dto.AcceptanceEventDto;
import com.gk.panda.apis.mapper.EventFlowRecordMapper;
import com.gk.panda.apis.service.EventFlowRecordService;
import com.gk.panda.pojo.EventFlowRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: EventFlowRecordServiceImpl
 * @Description: 待办事项的流转记录
 * @author: Sir.yang
 * @date: 2022/11/3 15:21
 * @version: 1.0
 **/
@Service
@Slf4j
public class EventFlowRecordServiceImpl extends ServiceImpl<EventFlowRecordMapper, EventFlowRecord> implements EventFlowRecordService {

    /**
     * @description: 根据事件ID获取该事件流转记录
     * @param: [eventId]
     * @return: java.util.List<com.gk.panda.pojo.EventFlowRecord>
     * @date: 2022/11/3 17:34
     * @version: 1.0
     **/
    @Override
    public List<EventFlowRecord> getEventFlowRecordListByEventId(Integer eventId) {
        QueryWrapper<EventFlowRecord> wrapper = new QueryWrapper<>();
        wrapper.eq(null != eventId, "event_id", eventId);
        return baseMapper.selectList(wrapper);
    }

    /**
     * @description: 添加流转记录，根据状态
     * @param: [AcceptanceEventDto]
     * @return: int
     * @date: 2022/11/3 23:09
     * @version: 1.0
     **/
    @Override
    public int saveRecordByStatus(AcceptanceEventDto dto, Integer status, String acceptance) {
        EventFlowRecord record = new EventFlowRecord();
        record.setEventId(dto.getEventId());
        record.setEventStatus(status);
        record.setOperationTime(new Date());
        record.setOperationDesc(acceptance);
        record.setRecipientName(dto.getRecipientName());
        record.setFkRecipient(dto.getFkRecipient());
        return baseMapper.insert(record);
    }


    /**
     * @description: 根据事件id和状态查询事件记录详情信息
     * @param: [eventId, status]
     * @return: com.gk.panda.pojo.EventFlowRecord
     * @date: 2022/11/4 9:32
     * @version: 1.0
     **/
    @Override
    public EventFlowRecord getEventFlowRecordByEventIdAndStatus(Integer eventId, Integer status) {
        QueryWrapper<EventFlowRecord> wrapper = new QueryWrapper<>();
        wrapper.eq(null != eventId, "event_id", eventId).eq(null != status,"event_status", status);
        return baseMapper.selectOne(wrapper);
    }
}
